import Vue from 'vue'
import App from './App'

//import Vant from 'vant'
//import 'vant/lib/index.css'
import uView from "uview-ui";
Vue.use(uView);
Vue.prototype.token = '';
Vue.config.productionTip = false


// 同步网络请求
const myRequest = (options) => {
	return new Promise((resolve, reject) => {
		// 封装主体：网络请求
		uni.request({
			url: Vue.prototype.$unishow + options.url,
			data: options.data || {},
			header: options.header || {},
			method: options.method || 'GET', // 默认值GET，如果有需要改动，在options中设定其他的method值
			success: (res) => {
				console.log(res.data); // 控制台显示数据信息
				resolve(res)
			},
			fail: (err) => {
				// 页面中弹框显示失败
				uni.showToast({
					title: '请求接口失败'
				})
				// 返回错误消息
				reject(err)
			}
		})
	})
}
Vue.prototype.$api = {
	myRequest,
};


Vue.prototype.$unishow = "https://www.dyszjx.com/";

//#ifdef H5

try {
	if(document.domain != 'localhost'){
		Vue.prototype.$unishow = '';
		var authDomain = uni.getStorageSync('authDomain');
		if (authDomain) {
			Vue.prototype.$unishow = 'https://'+authDomain+'/';
		    console.log(authDomain);
		}else{
			uni.request({
				url:"https://www.dyszjx.com/api/siteauth",
				method:'post',
				data:{domain:document.domain},
				success: (res) => {
					if(res.data.code){
						uni.setStorageSync('authDomain', document.domain);
						Vue.prototype.$unishow = document.domain;
						window.location.href = 'https://'+document.domain+'/client/index/';
					}
				}
			});
			console.log('没有授权');
		}
	}
} catch (e) {
    // error
	console.log('授权获取出错');
}

//#endif






Vue.prototype.$tourl = function(url) {
	if (url.slice(0, 4).toLowerCase() == 'http') {
		window.location.href = url;
	} else if (url.slice(0, 6).toLowerCase() == '/pages') {
		uni.navigateTo({
			url: url
		});
	} else {
		window.location.href = Vue.prototype.$unishow + url;
	}
}




//#ifdef H5
import wechat from './components/jweixin-module/wechat.js'
if (wechat.isWechat()) {
	Vue.prototype.$wechat = wechat;
}
//#endif



App.mpType = 'app'

const app = new Vue({
	...App
})
app.$mount()
